package com.web.dao;

import com.web.VO.DemandAcceptDetailVO;
import com.web.VO.DemandAcceptStateVO;
import com.web.VO.MyDemandVO;
import com.web.entity.DemandAccept;
import com.web.entity.DemandInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface DemandAcceptMapper {
    @Delete({
        "delete from APP_DEMAND_ACCEPT",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into APP_DEMAND_ACCEPT (demand_id, user_id, ",
        "create_time, modify_time)",
        "values (#{demandId,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, ",
        "#{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(DemandAccept record);

    int insertSelective(DemandAccept record);

    @Select({
        "select",
        "id, demand_id, user_id, create_time, modify_time",
        "from APP_DEMAND_ACCEPT",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    DemandAccept selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(DemandAccept record);

    @Update({
        "update APP_DEMAND_ACCEPT",
        "set demand_id = #{demandId,jdbcType=INTEGER},",
          "user_id = #{userId,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP},",
          "modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(DemandAccept record);

    /**
     * 查询用户是否重复接单
     * @param demandAccept
     * @return
     */
    DemandAccept selectIsExist(DemandAccept demandAccept);

    /**
     * 我的接单
     * @param userId
     * @return
     */
    List<MyDemandVO> getMyDemandInfo(String userId);

    /**
     * 根据id查询需求详情
     * @param demandId
     * @param userId
     * @return
     */
    DemandAcceptDetailVO getDemandDetail(@Param("demandId") Integer demandId, @Param("userId") String userId);

    /**
     * 接单情况
     * @param demandId
     * @return
     */
    List<DemandAcceptStateVO> listDemandAcceptState(Integer demandId);
}